from django.conf import settings
from itsdangerous.jws import TimedJSONWebSignatureSerializer as TJWSSerialize

# from users.models import User


# 加密密钥
def encode_password(username):

    serizlier = TJWSSerialize("111", expires_in=300)

    token = serizlier.dumps({'user': username})
    return token.decode()


def decode_password(token):
    serizlier = TJWSSerialize("111", expires_in=300)
    try:
        username = serizlier.loads(token).get('user')
    except Exception as e:
        return None
    return username

if __name__ == '__main__':
    a = encode_password({"username":"aaa"})
    print(a)
    b = decode_password(a)
    print(b)
